package com.ruoyi.controller.system;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.enums.UserIsAdminType;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.SysOrder;
import com.ruoyi.system.domain.SysUser;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysUserBillcash;
import com.ruoyi.system.service.ISysUserBillcashService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户资金流水记录Controller
 *
 * @author Ericcc
 * @date 2021-03-11
 */
@Controller
@RequestMapping("/system/billcash")
public class SysUserBillcashController extends BaseController
{
    private String prefix = "system/billcash";

    @Autowired
    private ISysUserBillcashService sysUserBillcashService;

    @RequiresPermissions("system:billcash:list")
    @GetMapping()
    public String billcash()
    {
        return prefix + "/billcash";
    }

    /**
     * 查询用户资金流水记录列表
     */
    @RequiresPermissions("system:billcash:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysUserBillcash sysUserBillcash)
    {
        startPage();
        // 取身份信息
        SysUser user = ShiroUtils.getSysUser();
        if (user.getUserType()== UserIsAdminType.COMMON.getCode()){
            sysUserBillcash.setUserCode(user.getUserCode());
        }else if(user.getUserType()== UserIsAdminType.AGENT.getCode()){
            Map map = new HashMap();
            map.put("parentId",user.getUserId());
            sysUserBillcash.setParams(map);
            List<SysUserBillcash> list = sysUserBillcashService.selectSysAgentUserBillcashList(sysUserBillcash);
            return getDataTable(list);
        }else if(user.getUserType()== UserIsAdminType.HIGHAGENT.getCode()){
            Map map = new HashMap();
            map.put("parentId",user.getUserId());
            sysUserBillcash.setParams(map);
            List<SysUserBillcash> list = sysUserBillcashService.selectSysHighAgentUserBillcashList(sysUserBillcash);
            return getDataTable(list);
        }
        List<SysUserBillcash> list = sysUserBillcashService.selectSysUserBillcashList(sysUserBillcash);
        return getDataTable(list);
    }

    /**
     * 导出用户资金流水记录列表
     */
    @RequiresPermissions("system:billcash:export")
    @Log(title = "用户资金流水记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysUserBillcash sysUserBillcash)
    {
        List<SysUserBillcash> list = sysUserBillcashService.selectSysUserBillcashList(sysUserBillcash);
        ExcelUtil<SysUserBillcash> util = new ExcelUtil<SysUserBillcash>(SysUserBillcash.class);
        return util.exportExcel(list, "billcash");
    }

    /**
     * 新增用户资金流水记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户资金流水记录
     */
    @RequiresPermissions("system:billcash:add")
    @Log(title = "用户资金流水记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysUserBillcash sysUserBillcash)
    {
        return toAjax(sysUserBillcashService.insertSysUserBillcash(sysUserBillcash));
    }

    /**
     * 修改用户资金流水记录
     */
    @GetMapping("/edit/{billcashId}")
    public String edit(@PathVariable("billcashId") Long billcashId, ModelMap mmap)
    {
        SysUserBillcash sysUserBillcash = sysUserBillcashService.selectSysUserBillcashById(billcashId);
        mmap.put("sysUserBillcash", sysUserBillcash);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户资金流水记录
     */
    @RequiresPermissions("system:billcash:edit")
    @Log(title = "用户资金流水记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysUserBillcash sysUserBillcash)
    {
        return toAjax(sysUserBillcashService.updateSysUserBillcash(sysUserBillcash));
    }

    /**
     * 删除用户资金流水记录
     */
    @RequiresPermissions("system:billcash:remove")
    @Log(title = "用户资金流水记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysUserBillcashService.deleteSysUserBillcashByIds(ids));
    }
}
